package Friday.th2;
public class Application {
    public static void main(String[] args) {
        //创建模拟器对象
        Simulator simulator=new Simulator();
        //传Animal子类的对象
        simulator.playSound(new Dog());
        simulator.playSound(new Cat());
    }
}
//模拟器类
class Simulator{
    //通过传Animal子类的对象实参创建上转型对象animal调用重写的方法
    public void playSound(Animal annimal){
        System.out.print(annimal.getAnimalName()+"的叫声");
        annimal.cry();
    }
}
//抽行类Animal
abstract class Animal{
    public abstract void cry();
    public abstract String getAnimalName();
}
//Animal子类：Dog
class Dog extends Animal{
    //继承的抽象方法要全部重写
    public void cry() {
        System.out.println("汪汪汪");
    }
    public String getAnimalName() {
        return "dog";
    }
}
//Animal子类Cat
class Cat extends Animal{
    //继承的抽象方法要全部重写
    public void cry() {
        System.out.println("喵喵喵");
    }
    public String getAnimalName() {
        return "cat";
    }
}